#include "TurnLampSleepState.h"
#include "F3LampInterfaces.h"
#include "LampManager.h"

TurnLampSleepStateMachine g_TurnLampSleepStateMachine;

void InitTurnLampSleepStateMachine(void)
{
    g_TurnLampSleepStateMachine.sm_.Entry = TurnLampSleepModeEntry;
    g_TurnLampSleepStateMachine.sm_.Excute = TurnLampSleepModeExcute;
    g_TurnLampSleepStateMachine.sm_.Exit = TurnLampSleepModeExit;
    g_TurnLampSleepStateMachine.sm_.waitExitCount_ = 0;
}

void TurnLampSleepModeEntry(void)
{
    // std::cout << "TurnLampSleepModeEntry" << std::endl;
    g_LeFrntTrunLampView.model_->mask = 0x00;
    g_LeFrntTrunLampView.model_->pwm_ = 0.0f;
    g_LeFrntTrunLampView.model_->onOffStatus_ = OnOff_Off;

    g_DayTimeAndPosLampView.model_->mask_ = 0x00;
    g_DayTimeAndPosLampView.model_->pwm_ = 0.0f;
    g_DayTimeAndPosLampView.model_->onOffStatus_ = OnOff_Off;

    g_StarrySkyView.model_->mask_ = 0x00;
    g_StarrySkyView.model_->pwm_ = 0.0f;
    g_StarrySkyView.model_->onOffStatus_ = OnOff_Off;
}

void TurnLampSleepModeExcute(void)
{
    OnOffFlag flag = OnOff_Initial;
    // OnOffFlag flag = LocalQuery_LeFrntTurnLampOnSt();
    // if(flag == OnOff_Off)
    // {
        g_SystemSleepWeakupModel.lampsOnOffMask_ |= LeTurn_Mask;
    // }

    float daytimeOrPosnLampBri = LocalQuery_LeFrntDaytimePosnLampBri();
    if(daytimeOrPosnLampBri == 0.0f)
    {
        g_SystemSleepWeakupModel.lampsOnOffMask_ |= DaytimeAndPosn_Mask;
    }

    flag = LocalQuery_StarrySkyLampsOnOffSt();
    if(flag == OnOff_Off)
    {
        g_SystemSleepWeakupModel.lampsOnOffMask_ |= StarrySky_Mask;
    }

    if(g_SystemSleepWeakupModel.lampsOnOffMask_ == 0xff)
    {
        SystemCtrl_StartSleep();
    }
}

void TurnLampSleepModeExit(void)
{
    // std::cout << "TurnLampSleepModeExit" << std::endl;
    g_SystemSleepWeakupModel.lampsOnOffMask_ = 0;
}
